package com.da.javalog.check.core;

import com.da.javalog.check.CheckRule;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * @author joker
 * @date 2020/04/28
 */
public class CheckerRegister {
    private static final Map<CheckRule, Checker> CHECKER_MAP = Maps.newConcurrentMap();

    public static void putChecker(CheckRule checkRule, Checker checker) {
        CHECKER_MAP.put(checkRule, checker);
    }

    public static Checker getChecker(CheckRule checkRule) throws CheckException {
        Checker checker = CHECKER_MAP.get(checkRule);
        if (checker == null) {
            throw new CheckException("[系统异常] 配置的校验规则没有找到对应实现！");
        }
        return CHECKER_MAP.get(checkRule);
    }
}
